package tn.vermeg.jee.tweetVermeg.main.presentation.controller;


import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import tn.vermeg.jee.tweetVermeg2.main.presentation.model.LoginModel;
import tn.vermeg.jee.tweetVermeg2.main.presentation.model.MainModel;
import tn.vermeg.jee.tweetVermeg2.main.presentation.model.TweetInfo;

import tn.vermeg.jee.tweetVermeg.model.Contact;
import tn.vermeg.jee.tweetVermeg.model.Tweet;
import tn.vermeg.jee.tweetVermeg.business.MainModule;


@ManagedBean(eager = true)
@SessionScoped
public class MainController implements Serializable {

    @EJB
    private Tweet selectedTweet=new Tweet();
    private Tweet tweet1=new Tweet();
    private String message;
    private MainModule business;
    private Contact curentUser;
    private LoginModel loginModel;
    private MainModel model = new MainModel(); //tjrs faire une instance du model et le nommer model
    //getter et setter !!!

    public Tweet getSelectedTweet() {
        return selectedTweet;
    }

    public void setSelectedTweet(Tweet selectedTweet) {
        this.selectedTweet = selectedTweet;
    }

    public Tweet getTweet1() {
        return tweet1;
    }

    public void setTweet1(Tweet tweet1) {
        this.tweet1 = tweet1;
    }

    public MainModule getBusiness() {
        return business;
    }

    public void setBusiness(MainModule business) {
        this.business = business;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void tweet() {
        TweetInfo newTweet = model.getNewTweet();
        Tweet tweet = new Tweet();
        tweet.setTitle(newTweet.getTitle());
        tweet.setMessage(newTweet.getMessage());
        model.getVisibleTweets().clear();
        //tweet.setContact(newTweet.getC());
        /*for(tweet t:buisiness.getNewTweet(){ model.getVisibleTweets().add(new TweetInfo(t.getTitle, t.getMessage()))});
        {
            model.setNewTweet;
        }*/
        
        model.getVisibleTweets().add(model.getNewTweet());
        model.setNewTweet(new TweetInfo());

        ////a completer

    }
    //getContact()
    public void replay2(){
     //   tweet1.setContact(loginModel.getContact());
        tweet1.setTweetAcestor(selectedTweet);
        tweet1.setDate(new Date());
        business.tweet(tweet1);
    }

    public void replay() {
        TweetInfo r = model.getReplayTweet();
        r.setIdAncestor(model.getReplayTweet().getId());
        model.getVisibleTweets().add(r);
        model.setReplayTweet(new TweetInfo());
    }

    public LoginModel getLoginModel() {
        return loginModel;
    }

    public void setLoginModel(LoginModel loginModel) {
        this.loginModel = loginModel;
    }

    public Contact getCurentUser() {
        return curentUser;
    }

    public void setCurentUser(Contact curentUser) {
        this.curentUser = curentUser;
    }

    public MainModule getBuisiness() {
        return business;
    }

    public void setBuisiness(MainModule business) {
        this.business = business;
    }

    /**
     * Creates a new instance of MainController
     */
    public MainController() {
    }

    public MainModel getModel() {
        return model;
    }

    public void setModel(MainModel model) {
        this.model = model;
    }
    public List<Tweet> getListeTweets(){
         
       // curentUser= loginModel.getContact();
        return business.getTweets(curentUser.getId());
        
    }
}


